﻿namespace Access.Duoc
{
    using ConfigDatabase.Class;
    using Npgsql;
    using Access;
    using BaseClass.Duoc;
    using System;
    using System.Data;

    public class DTheoDoiGiaBan
    {
        private ConnectDatabase _condata;
        private NpgsqlConnection _conn;
        private General _xuli;
        public int pLoaiXuat;

        public DTheoDoiGiaBan()
        {
            this.pLoaiXuat = 0;
            this._condata = new ConnectDatabase();
            this._xuli = new General(this._condata);
        }

        public DTheoDoiGiaBan(ConnectDatabase condata)
        {
            this.pLoaiXuat = 0;
            this._condata = condata;
            this._xuli = new General(this._condata);
        }

        public DataTable f_loaddata_theodoigia()
        {
            DataTable table = new DataTable();
            string str = this._condata.Schema + ".";
            string sql = "select a." + dtoDDMDuocPham.columnID + " as idsp,a." + dtoDDMDuocPham.columnTEN + " as tensp,a." + dtoDDMDuocPham.columnMA + " as masp,a." + dtoDDMDuocPham.columnDVT + " as dvt,a." + dtoDDMDuocPham.columnMAVACH + " as mavach,a2." + dtoDDMNhaSanXuat.columnTEN + " as tennhasx,b." + dtoDCapNhatGiaBan.columnIDDANGNHAP + " as iddangnhap,to_char(b." + dtoDCapNhatGiaBan.columnNGAYAPGIA + ",'dd/mm/yyyy hh24:mi') as ngayapgia,case when b." + dtoDCapNhatGiaBan.columnGIABANLE_CU + " is null then 0 else b." + dtoDCapNhatGiaBan.columnGIABANLE_CU + " end as giabanlecu,case when b." + dtoDCapNhatGiaBan.columnGIABANLE_MOI + " is null then 0 else b." + dtoDCapNhatGiaBan.columnGIABANLE_MOI + " end as giabanlemoi,case when b." + dtoDCapNhatGiaBan.columnGIABANSI_CU + " is null then 0 else b." + dtoDCapNhatGiaBan.columnGIABANSI_CU + " end as giabansicu,case when b." + dtoDCapNhatGiaBan.columnGIABANSI_MOI + " is null then 0 else b." + dtoDCapNhatGiaBan.columnGIABANSI_MOI + " end as giabansimoi from " + str + dtoDDMDuocPham.tableName + " a left join " + str + dtoDCapNhatGiaBan.tableName + " b on a." + dtoDDMDuocPham.columnID + "=b." + dtoDCapNhatGiaBan.columnIDSANPHAM + " left join " + str + dtoDDMNhaSanXuat.tableName + " a2 on a." + dtoDDMDuocPham.columnIDNHASX + "=a2." + dtoDDMNhaSanXuat.columnID + " order by b." + dtoDCapNhatGiaBan.columnNGAYAPGIA + " desc";
            return this._xuli.f_Get_dulieu(sql).Tables[0];
        }
    }
}

